TITLE: Tangent plane approximation
AUTHOR: Xavier Marcote

This applet is designed to aid in the understanding of how the tangent plane to a surface z=f(x,y) in a given point (P,f(P)) is obtained (P is in the domain of f), and how this plane can be used to provide an approximate 
value of f(P') for points P' close enough to P.
Inputs : - function z=f(x,y);
         - points P, P' in the xy-plane.
Outputs: - point P3D=(P,f(P)) on the surface z=f(x,y));
         - the gradient of f in P;
         - the normal vector n to the surface in P3D (construction in bidimensional auxiliary graphic);
         - the tangent plane to the surface in P3D; 
         - the value of f(P') and its approximation by the tangent plane in P3D.   

ACTIVITIES:

1) Enter the function f(x,y)=x^2+2y^2. In the lower-left graphic, click with the mouse on point P and drag it, and note how the unit vector u changes. Note that P3D=(P,f(P)) lies on the surface z=f(x,y).

2) Set point P to be P=(2,1) (if you prefer, you can write its coordinates in the box above instead of using mouse). Obtain analitically grad f(P), the gradient of f at point P (that is, the partial derivates of f 
   with respect to x and to y, at point P; result=(4,4)), compute the norm (modulus) of this vector, divide grad f(P) by this norm (obtaining unit vector u), and check that the result for u coincides with that shown 
   in the corresponding box (result: u=(1/sqrt(2),1/sqrt(2)).

3) In the graphic in the middle, note how vector (0,0,-1) is added to vector (grad f(P),0) to give vector n, that is normal (orthogonal) to the surface in point P3D=(P,f(P)).
 
4) Observe the equation of the tangent plane at point P3D. It is of the kind Ax+By+Cz=D, where (A,B,C)=n, and D is the value obtained by imposing that the plane contains point P3D. If P3D=(x0,y0,z0), a simple substitution yields
   D=Ax0+By0+Cz0; hence, the tangent plane can be written as Ax+By+Cz=Ax0+By0+Cz0 (or, equivalently, as  A(x-x0)+B(y-y0)+C(z-z0)=0). Check this for the current case, P=(2,1) and f(x,y)=x^2+2y^2. Watch the tangent plane in the 3D-graphic
   on the right.

5) Still taking f(x,y)=x^2+2y^2 and P=(2,1). Take a point P' close to P (in the domain of f, in the plane), and note the provided values in the boxes for f(P'), both the exact value and the approximated value given by the tangent plane 
   at P (at P3D, to be more precise). Drag P' so as to get closer and closer to P, and note how the two values for f(P') (exact and approximate) are more and more similar. This fact shows clearly that approximating the value of a function
   in a point P' by the tangent plane in another point P gives better results as P' is closer to P.

6) Repeat steps 1 to 5 for other surfaces z=f(x,y) and/or other points P, until you understand how a tangent plane at a point is calculated and how it can be used for obtaining approximated values of a function for close enough other points.
   What happens if f(x,y)=ax+by for two given real values a,b?